/*
 * @User 		@Company 	@Date
 * marcusbui	VNNET24  	May 20, 2011
 */
package tsb.com.html5.controller.base;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import tsb.com.html5.controller.common.CacheController;
import tsb.com.html5.exception.GenericException;

// TODO: Auto-generated Javadoc
/**
 * The Class BaseController.
 */
@Component
public abstract class BaseController{
	
	/** The logger. */
	protected final Log logger = LogFactory.getLog(getClass());
	
	/** The cache controller. */
	@Resource
	protected CacheController cacheController;

	/** The servlet context. */
	@Resource
	private ServletContext servletContext;
	
	/** The web application context. */
	@Resource
	private WebApplicationContext webApplicationContext;
	
	/**
	 * Gets the servlet context.
	 *
	 * @return the servlet context
	 */
	protected ServletContext getServletContext(){
		return servletContext;
	}
	
	/**
	 * Gets the application context.
	 *
	 * @return the application context
	 */
	protected WebApplicationContext getApplicationContext(){
		return webApplicationContext;
	}
	
	/**
	 * Gets the service.
	 *
	 * @param beanId the service id
	 * @return the service
	 * @throws Exception the exception
	 */
	protected Object getBean(String beanId) throws Exception{
		
		Object object = this.getApplicationContext().getBean(beanId);
		if(object == null){
			throw new GenericException("Bean not found");
		}
		return object;
	}
	
}
